package com.yl.chainStore.control.warehouse


import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.yl.chainStore.control.BaseCtrl
import com.yl.chainStore.entity.pay.SysCompanyPayItem
import com.yl.chainStore.pojo.vo.pay.SystemCompanyPayItemSelectVo
import com.yl.chainStore.services.warehouse.IWarehouseService
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnSuccess
import com.yl.common.getContext
import com.yl.users.common.annotations.PermsCode
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletResponse

/**
 * 仓库物品数量查询
 */
@RestController
@RequestMapping("warehouse/count")
open class WarehouseGoodsCountController(
	private val iWarehouseService: IWarehouseService
) : BaseCtrl() {



	/**
	 * 物品总数分页
	 */
	@RequestMapping("getGoodCountPage")
	@PermsCode("warehouse:count:getGoodCountPage")
	@Transactional
	open fun getGoodCountPage(@RequestBody body: SystemCompanyPayItemSelectVo): ResponseBody {
		return returnSuccess(
			iWarehouseService.getGoodPage(
				Page<SysCompanyPayItem>(body.current, body.size), body,
				getContext().subCompanyId
			)
		)
	}







	@GetMapping("export")
	@Transactional
	open fun export(@RequestBody body: SystemCompanyPayItemSelectVo,response:HttpServletResponse):ResponseBody{


		// TODO: 2021/7/14 暂不处理
		while(true){
			body.size = 100
			val goodPage = iWarehouseService.getGoodPage(
				Page<SysCompanyPayItem>(body.current, body.size), body,
				getContext().subCompanyId
			)
			if(goodPage.records.isEmpty()){
				break;
			}

			body.current++
		}

		return returnSuccess()
	}
}
